package com.karson.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Setter;

/**
 * @author ZKS
 */


public enum AgeRating implements BaseEnum {

    ALL(1, "全年龄"),
    MATURE(2, "R-15"),
    ADULT(3, "R-18");

    @EnumValue // 用于数据库持久化（MyBatis-Plus 会存这个值）
    @JsonValue // 用于 JSON 序列化
    private Integer code;

    private String name;

    AgeRating(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }

    public static AgeRating fromCode(int code) {
        for (AgeRating rating : AgeRating.values()) {
            if (rating.code == code) {
                return rating;
            }
        }
        throw new IllegalArgumentException("Invalid AgeRating code: " + code);
    }
}